package net.mikoo.seals.api.model.seal;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.common.model.PageModel;
import net.mikoo.seals.model.Seal;

public class SealListResponse extends BaseResponse {

	private static final long serialVersionUID = 1L;
	
	private List<SealInfo> seals;
	
	public List<SealInfo> getSeals() {
        return seals;
    }

    public void setSeals(List<SealInfo> seals) {
        this.seals = seals;
    }

    public static SealListResponse valueOf(PageModel<Seal> pm) {
		SealListResponse result = new SealListResponse();
		
		if(pm == null || pm.getDatas() == null || pm.getDatas().isEmpty()) {
			return result;
		}
		
		List<SealInfo> seals = new ArrayList<SealInfo>();
		for(Seal seal : pm.getDatas()) {
			
			SealInfo sealInfo = new SealInfo();
			sealInfo.setSealId(seal.getSealId());
			sealInfo.setSealName(seal.getSealName());
			if(!StringUtils.isBlank(seal.getSealName())) {
				sealInfo.setIconText(seal.getSealName().substring(0, seal.getSealName().length() < 2 ? 1 : 2));
			}
			sealInfo.setCustosPartyName(seal.getCustosName());
			sealInfo.setDevicesNum(seal.getDevicesList().size());
			sealInfo.setWorkflowId(seal.getWorkflowId());
			sealInfo.setSpecialWorkflowId(seal.getSpecialWorkflowId());
			sealInfo.setIsForcedPhoto(seal.getIsForcedPhoto());
			seals.add(sealInfo);
		}
		result.setSeals(seals);
		return result;
	}
	
}
